<?php
	if(!empty($_POST))
	{
		$errors = '';
		$myemail = 'tintas.graficas@tgv.com.pe';//<-----Put Your email address here.
		if(empty($_POST['txtnombre'])  ||
		   empty($_POST['txtapellidos']) ||
		   empty($_POST['txtcompania'])  ||
		   empty($_POST['txtpais'])  ||
		   empty($_POST['txtcalle'])  ||
		   empty($_POST['txtcod'])  ||
		   empty($_POST['txtciudad'])  ||
		   empty($_POST['txtemail']) ||
		   empty($_POST['info']) ||
		   empty($_POST['txtdescripcion']))
		{
			$errors .= "\n Error todos los campos son requeridos";
		}
		
		$name = $_POST['titulo']." ".$_POST['txtnombre']." ".$_POST['txtapellidos'];
		$com = $_POST['txtcompania'];
		$country = $_POST['txtpais'];
		$address = $_POST['txtcalle'];
		$cod = $_POST['txtcod'];
		$city = $_POST['txtciudad'];
		$state = $_POST['txtprov'];
		$tel = $_POST['txttelefono'];
		$email_address = $_POST['txtemail'];
		$info = $_POST['info'];
		$msg = $_POST['txtdescripcion'];
		
		if (!preg_match(
		"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", 
		$email_address))
		{
			$errors .= "\n Error la dirección de correo es invalida";
		}
		
		if(empty($errors))
		{
			$to = $myemail; 
			$email_subject = "Contacto Vencedor Tintas Gráficas ($name)";
			$email_body = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
			<html xmlns='http://www.w3.org/1999/xhtml'>
			<head>
			<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
			<title>Formulario de contacto</title>
			</head>
			
			<body>	
				<p><strong>Nombre:</strong> ".$name."</p>
				<p><strong>Email:</strong> <a href='mailto:".$email_address."'>".$email_address."</a></p>
				<p><strong>Empresa:</strong> ".$com."</p>
				<p><strong>País:</strong> ".$country."</p>
				<p><strong>Dirección:</strong> ".$address."</p>
				<p><strong>Código postal:</strong> ".$cod."</p>
				<p><strong>Ciudad:</strong> ".$city."</p>
				<p><strong>Estado/Provincia:</strong> ".$state."</p>
				<p><strong>Teléfono:</strong> ".$tel."</p>
				<p><strong>Solicitud de Información:</strong> ".$info."</p>
				<p><strong>Comentarios:</strong><p>
				<p>".$msg."<p>				
			</body>
			<html>";
	
			$headers = "Organization: TG Vencedor\r\n";	
			$headers .= "MIME-Version: 1.0\r\n"; 
			$headers .= "Content-type: text/html; charset=utf-8\r\n";
			$headers .= "X-Priority: 3\r\n";			
			$headers .= "From: Contacto Vencedor TG <$myemail>\r\n"; 
			$headers .= "Reply-To: $email_address\r\n";
			$headers .= "Return-Path: <$myemail>\r\n";
			
			$headers_to_client = "Organization: TG Vencedor\r\n";	
			$headers_to_client .= "MIME-Version: 1.0\r\n"; 
			$headers_to_client .= "Content-type: text/html; charset=utf-8\r\n";
			$headers_to_client .= "X-Priority: 3\r\n";
			$headers_to_client .= "From: Contacto Vencedor TG <$myemail>\r\n"; 
			$headers_to_client .=  "Return-Path: <$myemail>\r\n";
			
			$email_subject_client = "Vencedor Tintas Gráficas le saluda";
			$email_body_to_client = "
			<div style='text-align:center;' width='100%'>
			<table width='600' border='0' cellspacing='0' cellpadding='0' style='border:2px solid #ccc;'>
				  <tr>
					<td width='10'>&nbsp;</td>
					<td>&nbsp;</td>
					<td width='10'>&nbsp;</td>
				  
				  </tr>
				  <tr>
					<td></td>
					<td  align='center'><img border='0' alt='Vencedor Tintas Gráficas' src='http://ncom.pe/proy/vtg/img/logo.png' width='126' height='96'></td>
					<td>&nbsp;</td>
				  
				  </tr>
				  <tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				  
				  </tr>
				  <tr>
					<td>&nbsp;</td>
					<td>Estimado $name, hemos recibido su correo y que en breve lo contactaremos.</td>
					<td>&nbsp;</td>
				  
				  </tr>
				  
				   <tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				  
				  </tr>
				  
				  <tr>
					<td>&nbsp;</td>
					<td>Tintas Gráficas Vencedor S.A.<br>
				4596316 - 4596366 - 4596367</td>
					<td>&nbsp;</td>
				  
				  </tr>
				  
				   <tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				  
				  </tr>
			</table>
			</div>
			";
			
			mail($to,$email_subject,$email_body,$headers);
			mail($email_address,$email_subject_client,$email_body_to_client,$headers_to_client);
			
			//redirect to the 'thank you' page
			header('Location: envio.html');
		}
	}
?>